package com.xhsj.user.pms.patent.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhsj.user.generalprocess.mapper.TbPamGeneralNodeMapper;
import com.xhsj.user.generalprocess.vo.GeneralAuditHistoryVo;
import com.xhsj.user.hr.base.BaseParam;
import com.xhsj.user.pms.overseas.dto.GmMonitorListAduitDto;
import com.xhsj.user.pms.overseas.dto.PatentListByCountryNameDto;
import com.xhsj.user.pms.overseas.entity.TbPamOverseasCountryDict;
import com.xhsj.user.pms.overseas.query.CaseTreeListQuery;
import com.xhsj.user.pms.overseas.service.TbPamOverseasCountryDictService;
import com.xhsj.user.pms.patent.domain.TbPamOverseasApply;
import com.xhsj.user.pms.patent.domain.TbPamOverseasApplyCountry;
import com.xhsj.user.pms.patent.domain.TbPamOverseasApplyFile;
import com.xhsj.user.pms.patent.dto.FindRunTaskDto;
import com.xhsj.user.pms.patent.mapper.TbPamOverseasApplyCountryMapper;
import com.xhsj.user.pms.patent.mapper.TbPamOverseasApplyFileMapper;
import com.xhsj.user.pms.patent.mapper.TbPamOverseasApplyMapper;
import com.xhsj.user.pms.patent.query.OverseasApplyAuditTransferOutListQuery;
import com.xhsj.user.pms.patent.query.PatentListByCountryNameQuery;
import com.xhsj.user.pms.patent.vo.*;
import com.xhsj.user.utils.ExcelUtil;
import com.xhsj.user.utils.StringUtils;
import com.xhsj.user.utils.UserUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import com.xhsj.user.utils.Message;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;


import com.xhsj.user.pms.patent.service.TbPamOverseasApplyService;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


/**
 * <p>
 * 专利模块海外申请表
 * </p>
 *
 * @author suxiaolin
 * @since Jan 25, 2021 10:54:00 AM
 */
@Slf4j
@Api(tags = "专利模块海外申请表")
@RestController
@RequestMapping("/patent/tbPamOverseasApply")
public class TbPamOverseasApplyController {

    @Autowired
    public TbPamOverseasApplyService service;

    @Autowired
    private TbPamGeneralNodeMapper tbPamGeneralNodeMapper;

    @Autowired
    private TbPamOverseasApplyFileMapper tbPamOverseasApplyFileMapper;

    @Autowired
    private TbPamOverseasApplyMapper tbPamOverseasApplyMapper;

    @Autowired
    private TbPamOverseasApplyCountryMapper tbPamOverseasApplyCountryMapper;

    @Autowired
    public TbPamOverseasCountryDictService tbPamOverseasCountryDictService;

    @Autowired
    public ExcelUtil excelUtil;


    /**
     * 保存/修改
     *
     * @author suxiaolin
     * @date Jan 25, 2021 10:54:00 AM
     */
    @ApiOperation(value = "专利模块海外申请表,保存/修改", notes = "专利模块海外申请表,保存和修改方法")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
//    @PreAuthorize("hasAuthority('tb:pam:overseas:apply:edit')")
    public Message save(@RequestBody TbPamOverseasApply data) {
        try {
            service.startProcess(data);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("保存失败:{}", e);
            return Message.error(1, e.getMessage());
        }

    }

    /**
     * 查询正在执行中任务
     *
     * @author 苏小林
     * @date 2021/1/27 15:29
     * @param: baseParam
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/findRunTask", method = RequestMethod.POST)
    public Message findRunTask(@RequestBody @Valid FindRunTaskDto baseParam, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            log.info(bindingResult.getFieldError().getDefaultMessage());
            return Message.error(1,bindingResult.getFieldError().getDefaultMessage());
        }
        try {
            IPage<FindRunTaskVo> selectPage = service.findRunTask(baseParam);
            return Message.success("成功", selectPage.getRecords(), selectPage.getTotal(), selectPage.getPages());
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    /**
     * 查询历史任务
     *
     * @author 苏小林
     * @date 2021/1/27 15:30
     * @param: baseParam
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/findHiTask", method = RequestMethod.POST)
    public Message findHiTask(@RequestBody FindRunTaskDto baseParam) {

        try {
            IPage<FindHiTaskVo> selectPage = service.findHiTask(baseParam);
            return Message.success("成功", selectPage.getRecords(), selectPage.getTotal(), selectPage.getPages());
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    /**
     * 通过id获取实体类
     *
     * @author suxiaolin
     * @date Jan 25, 2021 10:54:00 AM
     */
    @ApiOperation(value = "通过id获取专利模块海外申请表实体类", notes = "通过id获取专利模块海外申请表实体类。")
    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    public Message getById(@RequestParam(value = "dataId") Long dataId) {


        TbPamOverseasApply tbPamOverseasApply = service.getByDataId(dataId);

        return Message.success("成功", tbPamOverseasApply);
    }

    /**
     * 处理流程10-技术负责人(LED高级工艺工程师)审核进入国家
     *
     * @author 苏小林
     * @date 2021/3/9 16:05
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/handleProcessNode_10", method = RequestMethod.POST)
    public Message handleProcessNode_10(@RequestBody @Valid EnterCountryVo enterCountryVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            for (ObjectError allError : bindingResult.getAllErrors()) {
                if (enterCountryVo.getStatus() == 0 && !allError.getObjectName().equals("countryNames")) {
                    log.error("参数校验:{}", allError.getDefaultMessage());
                    return Message.error(1, allError.getDefaultMessage());
                }
            }
        }
        try {
            service.handleProcessNode_10(enterCountryVo);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 处理流程11-总经理审核(立案)
     *
     * @author 苏小林
     * @date 2021/3/9 16:17
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/handleProcessNode_11", method = RequestMethod.POST)
    public Message handleProcessNode_11(@RequestBody @Valid EnterCountryVo enterCountryVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            for (ObjectError allError : bindingResult.getAllErrors()) {
                log.error("参数校验:{}", allError.getDefaultMessage());
                return Message.error(1, allError.getDefaultMessage());
            }
        }

        try {
            service.handleProcessNode_11(enterCountryVo);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 处理流程节点2-流程专员编写案例（立案）
     *
     * @author 苏小林
     * @date 2021/1/27 15:43
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/handleProcessNode_2", method = RequestMethod.POST)
    public Message handleProcessNode_2(@RequestBody OverseasApplyAuditVo entity) {

        try {
            service.handleProcessNode_2(entity);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 处理流程节点2-IPR编写完整申请文件
     *
     * @author 苏小林
     * @date 2021/1/27 15:43
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/handleProcessNode_3", method = RequestMethod.POST)
    public Message handleProcessNode_3(@RequestBody OverseasApplyAuditVo entity) {


        try {
            service.handleProcessNode_3(entity);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    /**
     * 处理流程节点4和节点5-主管审核和总经理审核(提交)
     *
     * @author 苏小林
     * @date 2021/1/27 15:43
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/handleProcessNode_4_5", method = RequestMethod.POST)
    public Message handleProcessNode_4_5(@RequestBody OverseasApplyAuditVo entity) {
        try {
            service.handleProcessNode_4_5(entity);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 查询进度
     *
     * @author 苏小林
     * @date 2021/1/28 17:53
     * @param: dataId
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/getProgress", method = RequestMethod.GET)
    public Message getProgress(@RequestParam("dataId") Long dataId) {
        try {
            JSONObject jsonObject = new JSONObject();
            TbPamOverseasApply byId = service.getById(dataId);
            int execOrder = 10;
            if ("闭案".equals(byId.getNodeName())) {
                List<Map<String,Object>> opinionText = service.getNewNodeIdByDataId(dataId);
                List<Map<String, Object>> collect = opinionText.stream()
                        .sorted(Comparator.comparing(e -> String.valueOf(e.get("updateDate"))))
                        .collect(Collectors.toList());
                execOrder = 9;
                jsonObject.put("nodeList", collect);
            }else {
                List<ProcessNodeVo> list = tbPamGeneralNodeMapper.getNodeListByProcessType("foreign_apply");
                if (!"完结".equals(byId.getNodeName())) {
                    ProcessNodeVo processNodeVo1 = list.stream().filter(processNodeVo -> processNodeVo.getNodeId() == byId.getNodeId()).findAny().get();
                    execOrder = processNodeVo1.getExecOrder();
                }
                jsonObject.put("nodeList", list);
            }

            jsonObject.put("cutNodeId", execOrder);

            return Message.success("成功", jsonObject);
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }

    }

    /**
     * 查询审核历史
     *
     * @author 苏小林
     * @date 2021/1/28 18:00
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/getAuditHistory", method = RequestMethod.GET)
    public Message getAuditHistory(@RequestParam("dataId") Long dataId,
                                   @RequestParam(value = "page", defaultValue = "1") int page,
                                   @RequestParam(value = "size", defaultValue = "20") int size) {

        try {
            IPage<GeneralAuditHistoryVo> selectPage = service.getAuditHistory(dataId, page, size);
            return Message.success("成功", selectPage.getRecords(), selectPage.getTotal(), selectPage.getPages());
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }

    }

    /**
     * 处理流程节点6-处理委托提交
     *
     * @author 苏小林
     * @date 2021/1/27 15:43
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/handleProcessNode_6", method = RequestMethod.POST)
    public Message handleProcessNode_6(@RequestBody OverseasApplyAuditVo entity) {
        try {
            service.handleProcessNode_6(entity);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    /**
     * 处理流程节点7-处理授权通过
     *
     * @author 苏小林
     * @date 2021/1/27 15:43
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/handleProcessNode_7", method = RequestMethod.POST)
    public Message handleProcessNode_7(@RequestBody OverseasApplyAuditVo entity) {
        try {
            service.handleProcessNode_7(entity);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 查询文件列表
     *
     * @author 苏小林
     * @date 2021/2/2 13:19
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/getFileListByDataId", method = RequestMethod.POST)
    public Message getFileListByDataId(@RequestBody BaseParam baseParam) {
        try {

            Page<TbPamOverseasApplyFile> page = new Page<>(baseParam.getPage(), baseParam.getSize());
            IPage<TbPamOverseasApplyFile> selectPage = tbPamOverseasApplyFileMapper.getFileListByDataId(page, baseParam.getId());
            return Message.success("成功", selectPage.getRecords(), selectPage.getTotal(), selectPage.getPages());
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 查询文件类型列表
     *
     * @author 苏小林
     * @date 2021/2/2 13:47
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/getFileTypeList", method = RequestMethod.GET)
    public Message getFileTypeList(@RequestParam(required = false) String type) {
        try {
            if (StringUtils.isBlank(type)) {
                type = "overseas_apply";
            }
            List<Map<String, String>> list = tbPamOverseasApplyFileMapper.getFileTypeList(type);
            return Message.success("成功", list);
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 删除文件
     *
     * @author 苏小林
     * @date 2021/2/2 15:47
     * @param: id
     * @param: path
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/deleteOverseasApplyFile", method = RequestMethod.GET)
    public Message deleteOverseasApplyFile(@RequestParam("id") Long id, @RequestParam("path") String path) {

        try {
            service.deleteOverseasApplyFile(id, path);
            return Message.success("成功");
        } catch (IOException e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }

    }


    /**
     * 上传文件
     *
     * @author 苏小林
     * @date 2021/2/2 15:13
     * @param: entity
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/saveOverseasApplyFile", method = RequestMethod.POST)
    public Message saveOverseasApplyFile(@RequestBody TbPamOverseasApplyFile entity) {

        try {
            Long overseasApplyId = entity.getOverseasApplyId();
            if (overseasApplyId == null) {
                throw new Exception("dataId为空");
            }

            Integer fileType = entity.getFileType();
            if (fileType == null) {
                throw new Exception("请先选择文件类型");
            }

            entity.setCreateBy(UserUtils.getLoginAppUser().getUserId());
            entity.setCreateName(UserUtils.getLoginAppUser().getFullName());
            entity.setCreateDate(new Date());
            entity.setUpdateDate(new Date());

            tbPamOverseasApplyFileMapper.insert(entity);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("失败:{}", e);
            try {
                service.deleteFile(entity.getFileUrl());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 保存数据接口
     *
     * @author 苏小林
     * @date 2021/3/2 16:12
     * @param: entity
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/saveData", method = RequestMethod.POST)
    public Message saveData(@RequestBody OverseasApplyAuditVo entity) {

        try {
            service.saveData(entity);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("保存出错", e);
            return Message.error(1, e.getMessage());
        }

    }

    /**
     * @Description: 国内案件提醒ipr流程专员审批
     * @Param:com.xhsj.user.pms.overseas.dto.GmMonitorListAduitDto
     * @return:Message
     * @Author: liuqinghua
     * @Date: 2021/1/26
     */
    @ApiOperation(value = "国内案件提醒ipr流程专员审批", notes = "国内案件提醒ipr流程专员审批")
    @PostMapping(value = "/gmMonitorListAduit")
    public Message gmMonitorListAduit(@RequestBody @Valid GmMonitorListAduitDto param, BindingResult bindingResult) {
        try {
            log.info("国内案件提醒ipr流程专员审批参数{}", param);
            if (bindingResult.hasErrors() && param.getStatus() == 0) {
                log.info(bindingResult.getFieldError().getDefaultMessage());
                return Message.error(1, bindingResult.getFieldError().getDefaultMessage());
            }
            service.gmMonitorListAduit(param);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("保存失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    @ApiOperation(value = "国内案件提醒ipr流程专员重新提交", notes = "国内案件提醒ipr流程专员重新提交")
    @PostMapping(value = "/gmMonitorListReAduit")
    public Message gmMonitorListReAduit(@RequestBody @Valid OverseasApplyAuditVo param, BindingResult bindingResult) {
        try {
            log.info("国内案件提醒ipr流程专员重新审批参数{}", param);
            if (bindingResult.hasErrors() && param.getStatus() == 0) {
                log.info(bindingResult.getFieldError().getDefaultMessage());
                return Message.error(1, bindingResult.getFieldError().getDefaultMessage());
            }
            service.gmMonitorListReAduit(param);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("保存失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    /**
     * @Description: 国内案件提醒总经理审批页面展示
     * @Param:disclosureId交底书id
     * @Author: liuqinghua
     * @Date: 2021/2/2
     */
    @ApiOperation(value = "国内案件提醒ipr流程专员审批页面展示", notes = "国内案件提提醒ipr流程专员审批页面展示")
    @GetMapping(value = "/gmMonitorListAduitPageView")
    public Message gmMonitorListAduitPageView(@RequestParam(value = "disclosureId") String disclosureId) {
        try {
            log.info("国内案件提醒提醒ipr流程专员审批页面展示参数{}", disclosureId);
            Map<String, Object> objects = service.gmMonitorListAduitPageView(disclosureId);
            return Message.success("成功", objects);
        } catch (Exception e) {
            log.error("保存失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    /**
     * @Description: 案件树
     * @Author: liuqinghua
     * @Date: 2021/1/26
     */
    @ApiOperation(value = "案件树", notes = "案件树")
    @GetMapping(value = "/caseTreeList")
    public Message caseTreeList(@RequestParam(value ="searchName",required = false) String searchName) {
        try {
            Set<CaseTreeListQuery> caseTreeListQueries = service.caseTreeList(searchName);
            return Message.success("成功", caseTreeListQueries);
        } catch (Exception e) {
            log.error("保存失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    /**
     * 查询所有海外案件申请数据
     *
     * @author 苏小林
     * @date 2021/3/1 16:22
     * @param: data
     * @return: com.xhsj.user.utils.Message
     */
    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:pam:overseas:apply:view')")
    public Message findList(@RequestBody Map<String, Object> data) {
        try {
//			IPage<TbPamOverseasApply> selectPage = service.selectPage(data);
            IPage<OverseasApplyListVo> selectPage = service.findApplyList(data);
            return Message.success("成功", selectPage.getRecords(), selectPage.getTotal());
        } catch (Exception e) {
            log.error("查询异常:{}", e);
            return Message.error(1, "失败");
        }
    }

    /**
     * 保存海外申请国家字典
     *
     * @author 苏小林
     * @date 2021/3/10 15:26
     * @param: countryName
     * @return: com.xhsj.user.utils.Message
     */
    @GetMapping(value = "/saveCountryDict")
    public Message saveCountryDict(@RequestParam("countryName") String countryName) {

        try {
            //    		判断是否已存在
            QueryWrapper<TbPamOverseasCountryDict> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("name",countryName);
            List<TbPamOverseasCountryDict> list = tbPamOverseasCountryDictService.list(queryWrapper);
            if (list.size() > 0) {
                return Message.error(1,"国家已存在");
            }
            tbPamOverseasApplyMapper.saveCountryDict(countryName);
            return Message.success();
        } catch (Exception e) {
            log.error("查询异常:{}", e);
            return Message.error(1, "失败");
        }
    }

    /**
     * 查询海外国家字典
     *
     * @author 苏小林
     * @date 2021/3/10 15:30
     * @return: com.xhsj.user.utils.Message
     */
    @GetMapping(value = "/getCountryDict")
    public Message getCountryDict() {

        try {
            List<Map<String, String>> list = tbPamOverseasApplyMapper.getCountryDict();
            return Message.success("success", list);
        } catch (Exception e) {
            log.error("查询异常:{}", e);
            return Message.error(1, "失败");
        }

    }

    /**
     * 查询申请数据选择的国家信息列表
     *
     * @author 苏小林
     * @date 2021/3/10 16:10
     * @param: dataId
     * @return: com.xhsj.user.utils.Message
     */
    @GetMapping(value = "/getCountryListByApplyId")
    public Message getCountryListByApplyId(@RequestParam("dataId") Long dataId) {

        try {
            TbPamOverseasApplyCountry tbPamOverseasApplyCountry = tbPamOverseasApplyCountryMapper.findListByDataId(dataId);
            String countryName = tbPamOverseasApplyCountry.getCountryName();
            List<String> list = new ArrayList<>();
            if(StringUtils.isNotBlank(countryName)){
               list = Arrays.asList(countryName.split(","));
            }
            return Message.success("success", list);
        } catch (Exception e) {
            log.error("查询异常:{}", e);
            return Message.error(1, "失败");
        }

    }


    /**
     * 获取申请类型列表
     * @author 苏小林
     * @date 2021/3/11 14:03
     * @return: com.xhsj.user.utils.Message
     */
    @GetMapping(value = "/getApplyTypeList")
    public Message getApplyTypeList() {
        try {
            List<Map<String, String>> list = tbPamOverseasApplyMapper.getApplyTypeList();
            return Message.success("success", list);
        } catch (Exception e) {
            log.error("查询异常:{}", e);
            return Message.error(1, "失败");
        }
    }

    /**
     * 获取节点列表
     * @author 苏小林
     * @date 2021/3/11 17:13
     * @return: com.xhsj.user.utils.Message
     */
    @GetMapping(value = "/getNodeList")
    public Message getNodeList() {
        try {
            List<ProcessNodeVo> list = tbPamGeneralNodeMapper.getNodeList("foreign_apply");
            return Message.success("success", list);
        } catch (Exception e) {
            log.error("查询异常:{}", e);
            return Message.error(1, "失败");
        }
    }

       /**
           * @Description: 根据国家名获取数据
           * @Param: PatentListByCountryNameDto
           * @return:
           * @Author: liuqinghua
           * @Date: 2021/6/1
           */
    @PostMapping(value = "/getPatentListByCountryName")
    public Message getPatentListByCountryName(@RequestBody PatentListByCountryNameDto data, BindingResult bindingResult) {
        try {
            if(bindingResult.hasErrors()){
                System.out.println(bindingResult.getFieldError().getDefaultMessage());
            }
            IPage<PatentListByCountryNameQuery> list = service.getPatentListByCountryName(data);
            return Message.success("success", list.getRecords(),list.getTotal(),list.getPages());
        } catch (Exception e) {
            log.error("查询异常:{}", e);
            return Message.error(1, "失败");
        }
    }

       /**
           * @Description: 获取意见
           * @Param:  dataId业务id
           * @return:  List<Map<String,String>>
           * @Author: liuqinghua
           * @Date: 2021/6/16
           */
    @RequestMapping(value = "/getOpinionTextByNodeId", method = RequestMethod.GET)
    public Message getOpinionTextByNodeId(@RequestParam("dataId") Long dataId) {
        try {
            List<Map<String,Object>> opinionText = service.getOpinionTextByNodeId(dataId);
            return Message.success("成功", opinionText);
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }

    }
    
       /**
           * @Description: 删除我的海外专利
           * @Param:  dataId 业务id
           * @return:  
           * @Author: liuqinghua
           * @Date: 2021/6/22 
           */
       @RequestMapping(value = "/deleteMyOverseasApply", method = RequestMethod.GET)
       public Message deleteMyOverseasApply(@RequestParam("id") Long id) {
           try {
                service.deleteMyOverseasApply(id);
               return Message.success("成功");
           } catch (Exception e) {
               log.error("失败:{}", e);
               return Message.error(1, e.getMessage());
           }

       }


    /***
     * 查询转出海外专利审核任务列表
     * @author 苏小林
     * @date 2021/6/22 13:16
     * @return: com.xhsj.user.utils.Message
     */
    @PostMapping("/findOverseasApplyAuditTransferOutList")
    public Message findOverseasApplyAuditTransferOutList(@RequestBody OverseasApplyAuditTransferOutListQuery entity) {

        try {
            IPage<OverseasApplyAuditTransferOutListVo> selectPage = service.findOverseasApplyAuditTransferOutList(entity);
            return Message.success("成功", selectPage.getRecords(), selectPage.getTotal(), selectPage.getPages());
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }

    /***
     * 查询转入海外专利审核任务列表
     * @author 苏小林
     * @date 2021/6/22 13:16
     * @return: com.xhsj.user.utils.Message
     */
    @PostMapping("/findOverseasApplyAuditTransferInList")
    public Message findOverseasApplyAuditTransferInList(@RequestBody OverseasApplyAuditTransferOutListQuery entity) {

        try {
            IPage<OverseasApplyAuditTransferOutListVo> selectPage = service.findOverseasApplyAuditTransferInList(entity);
            return Message.success("成功", selectPage.getRecords(), selectPage.getTotal(), selectPage.getPages());
        } catch (Exception e) {
            log.error("失败:{}", e);
            return Message.error(1, e.getMessage());
        }
    }


    // 数据修改
    @GetMapping("/overSeas/v1")
    @ApiOperation(value = "数据修改2", notes = "数据修改2")
    public void overSeas(String archivesNum,String pArchivesNum,String countryNames,int type) throws Exception {
        // sheet

        service.overSeas(archivesNum,pArchivesNum,countryNames,type);
    }

    // 数据修改

    @RequestMapping(value = {"/overSeas/test"}, method = RequestMethod.POST, consumes = "multipart/form-data")
    @ApiOperation(value = "数据修改2", notes = "数据修改2")
    @ResponseBody
    public Message overSeas1(@RequestParam("file") MultipartFile file,@RequestParam("countryNames") String countryNames) throws Exception {
        // sheet
        List<Map> list = excelUtil.importExcelWithSimple(file);
        for (Map map:list){
            String archivesNum = String.valueOf(map.get("archivesNum"));
            String pArchivesNum =String.valueOf( map.get("pArchivesNum"));
            int type = Integer.parseInt(String.valueOf(map.get("type")));
            service.overSeas(archivesNum,pArchivesNum,countryNames,type);
        }

        return Message.success("成功",list);

    }


}

